/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import javax.swing.JOptionPane;
import src.ClaseCargo;
import src.Core;

/**
 *
 * @author Strauzen
 */
public class VentanaTiempo extends javax.swing.JFrame {
    int padre;
    VentanaPersonaje vp;
    VentanaModificarRelaciones vmr;
    Ventana1 v1;
    Ventana3 v3;
    
    /**
     * Creates new form VentanaTiempo
     */
    public VentanaTiempo(int padre, Ventana1 v1, Ventana3 v3, VentanaPersonaje vp) {
        this.padre = padre;
        this.vp = vp;
        this.v1 = v1;
        this.v3 = v3;
        initComponents();
    }
    
    public VentanaTiempo(int padre, VentanaModificarRelaciones vmr,int idPadre) {
        this.padre = padre;
        this.idpadre = idPadre;
        this.vmr = vmr;
        initComponents();
    }

            private boolean comprobar(){
        String mensaje = "";
        boolean resultado = true;
          
        try{
            Integer.parseInt(this.jTextField_vtFechaIni.getText());
            Integer.parseInt(this.jTextField_vtFechaFin.getText());
            if(this.jTextField_vtFechaIni.getText().length() != 8 || this.jTextField_vtFechaFin.getText().length() != 8)
                throw new Exception();
            
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Por favor rellene las fechas de la siguiente manera:\n"
                    + "ej. 20120101 siendo los 4 primeros numeros el año, los dos siguientes el mes\n"
                    + "y los dos ultimos el día\n\n");
            resultado = false;
        }
              
        return resultado;
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel_vtFechaIni = new javax.swing.JLabel();
        jTextField_vtFechaIni = new javax.swing.JTextField();
        jLabel_vtFechaFin = new javax.swing.JLabel();
        jTextField_vtFechaFin = new javax.swing.JTextField();
        jButton_vtTerminar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Periodo durante el que se ocupo el cargo");

        jLabel_vtFechaIni.setText("Fecha de inicio");

        jLabel_vtFechaFin.setText("Fecha de Finalizacion");

        jButton_vtTerminar.setText("Terminar");
        jButton_vtTerminar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_vtTerminarMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel_vtFechaIni)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField_vtFechaIni, javax.swing.GroupLayout.DEFAULT_SIZE, 333, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel_vtFechaFin)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField_vtFechaFin, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(0, 332, Short.MAX_VALUE)
                        .addComponent(jButton_vtTerminar))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_vtFechaIni)
                    .addComponent(jTextField_vtFechaIni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_vtFechaFin)
                    .addComponent(jTextField_vtFechaFin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_vtTerminar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_vtTerminarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_vtTerminarMouseClicked
        // TODO add your handling code here:
        if(comprobar()){
            ClaseCargo CC = new ClaseCargo(-1, Integer.parseInt(jTextField_vtFechaIni.getText()), Integer.parseInt(jTextField_vtFechaFin.getText()));
            switch(padre){
                case 1:                 
                    VentanaCargo vc = new VentanaCargo(v1,v3,vp,CC);
                    vc.setVisible(true);
                    this.setVisible(false);
                    this.dispose();
                    break;
                case 2:
                    this.setVisible(false);
                    VentanaAnadir va = new VentanaAnadir(4,v1,v3,vp,CC);
                    va.setTexto(Core.dameTodosCargos());
                    if("".equals(va.getTexto())){
                        vp.setVisible(true);
                    }else {
                        va.setVisible(true);
                    }
                    this.dispose();
                    break;
                case 3:
                    this.setVisible(false);
                    VentanaAnadir va2 = new VentanaAnadir(14,vmr,CC,idpadre);
                    va2.setTexto(Core.dameTodosCargos());
                    if("".equals(va2.getTexto())){
                        vmr.setVisible(true);
                    }else {
                        va2.setVisible(true);
                    }
                    this.dispose();
                    break;
            }  
        }
    }//GEN-LAST:event_jButton_vtTerminarMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_vtTerminar;
    private javax.swing.JLabel jLabel_vtFechaFin;
    private javax.swing.JLabel jLabel_vtFechaIni;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextField_vtFechaFin;
    private javax.swing.JTextField jTextField_vtFechaIni;
    // End of variables declaration//GEN-END:variables
    private int idpadre;
}
